package org.example.aaaatest.a1;

import com.amap.car.order.i18n.util.TimeZoneUtil;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @description:
 * @author: wangbaogui
 * @create: 2025/4/9 21:44
 **/
public class c1 {
    // 获取第一个地区的时间
    public static void main(String[] args) {
        TimeZone timeZone = TimeZoneUtil.getAdminTimeZone( 35.713246,139.762315);
        ZoneId zoneId = timeZone.toZoneId();
        System.out.println("zoneId = " + zoneId);

        // 第二个时区的 ZoneId
        ZoneId eastEightZoneId = ZoneId.of("Asia/Shanghai");

        // 获取当前时间的 Instant 对象
        ZonedDateTime zonedDateTime1 = ZonedDateTime.now(zoneId);
        ZonedDateTime zonedDateTime2 = ZonedDateTime.now(eastEightZoneId);

        // 计算时间差（以毫秒为单位）
        long millisecondsDifference = ChronoUnit.MILLIS.between(zonedDateTime1, zonedDateTime2);

        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MILLISECOND, (int)(millisecondsDifference * 1000));

        // 获取修改后的Date对象
        Date newDate = calendar.getTime();


        System.out.println("differenceHours = " + newDate);


        Instant now = Instant.now();
        ZoneOffset offset1 = zoneId.getRules().getOffset(now);
        ZoneOffset offset2 = eastEightZoneId.getRules().getOffset(now);

        long diffMillis = (offset2.getTotalSeconds() - offset1.getTotalSeconds()) * 1000L;
        System.out.println("相差毫秒数：" + diffMillis);


        long timeInMillis = date.getTime();

        // 加上毫秒数
        timeInMillis += diffMillis;

        // 设置新的时间
        date.setTime(timeInMillis);

        System.out.println("date = " + date);

    }
}
